//
//  CommissionListViewController.m
//  OrderFood
//
//  Created by xiaofang wang on 2018/12/29.
//  Copyright © 2018年 zhiyuan. All rights reserved.
//

#import "CommissionListViewController.h"
@interface CommissionCell:UITableViewCell
@end

@implementation CommissionCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:UITableViewCellStyleValue1
                    reuseIdentifier:reuseIdentifier]) {
        
    }
    return self;
}
@end

//==============================
@interface CommissionModel : NSObject
/**0.开始时间*/
@property (nonatomic, strong) NSNumber *startingTime;
/**1.endTime*/
@property (nonatomic, strong) NSNumber *workTime;
@property (nonatomic, strong) NSNumber *hourlyWage;
@property (nonatomic, strong) NSNumber *changes;
@property (nonatomic, strong) NSNumber *orderFreight;
@property (nonatomic, strong) NSNumber *subsidy;
@property (nonatomic, strong) NSNumber *salary;
@property (nonatomic, strong) NSNumber *createTime;
@end

@implementation CommissionModel

@end

//==============================
@interface CommissionListViewController ()<UITableViewDelegate,UITableViewDataSource>

/**数据源*/
@property (nonatomic, strong) NSMutableArray *dataArrayM;

@end

@implementation CommissionListViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    [self requestData];
    [self fakeData];
    
    self.name = @"佣金结算明细";
    [self setupUI];
}


- (void)setupUI {
    CGRect tableViewFrame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-SafeAreaTopHeight-TabBar_HEIGHT-MHTitilesViewH - SafeAreaBottomHeight);
    self.tableview = [[UITableView alloc] initWithFrame:tableViewFrame];
    
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    [self.view addSubview:self.tableview];
    
    //注册cell
    [self.tableview registerClass:[CommissionCell class] forCellReuseIdentifier:@"CommissionCell"];
    
    self.tableview.tableFooterView = [UIView new];
}


- (NSMutableArray *)dataArrayM {
    if (!_dataArrayM) {
        _dataArrayM = [NSMutableArray array];
    }
    return _dataArrayM;
}


#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArrayM.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CommissionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommissionCell"];

    CommissionModel *model = self.dataArrayM[indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"+%@",model.orderFreight]; //这个应该显示 “配送费”
 
    cell.textLabel.textColor = [UIColor rb_colorWithHex:0x4A8A39];
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

#pragma mark - 网络请求

- (void)fakeData {
    
    NSDictionary *dic = @{@"startingTime":@"1544604396000",
                          @"endTime":@"1544608814000",
                          @"workTime":@"4418",
                          @"hourlyWage":@"200000",
                          @"changes":@"10",
                          @"orderFreight":@"3",
                          @"subsidy":@"100",
                          @"salary":@"246990",
                          @"createTime":@"1544608814000"
                          };
    
    CommissionModel *model = [CommissionModel mj_objectWithKeyValues:dic];
    [self.dataArrayM addObject:model];
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.tableview reloadData];
    });
    
}


- (void)requestData {
    
    [IndicatorManager showOperateBegin:@""];
    
    [NetWork requestCommissionListSuccessBlock:^(NSDictionary * _Nonnull response) {
        [IndicatorManager dismissHuD];
        if (RES_SUCESS) {//解析数据
            
            NSArray *tempArr = response[@"data"];
            for (NSDictionary *dic in tempArr) {
                CommissionModel *model = [CommissionModel mj_objectWithKeyValues:dic];
                
                [self.dataArrayM addObject:model];
            }
            
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.tableview reloadData];
            });
        }else {
            [IndicatorManager showFailure:MESSAGE];
        }
    } failBlock:^(NSString * _Nonnull message) {
        [IndicatorManager dismissHuD];
        [IndicatorManager showFailure:message];
    }];
}


- (void)showAlertWithModel:(CommissionModel *)model {
    
}
@end
